// https://soj.turingedu.cn/problem/50300/
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
int rad(); // read int
const int max_size = 5 + 100;
const int maxn = 5 + 1e6;

int n;
int a[maxn], f[maxn];
int min_ed[maxn]; // min_ed[i] 表示长度为 i 的最长上升子序列结尾的最小值

inline int bin_search(int *a, int l, int r, int val) { // the max index of less than val
    if (a[l] >= val) return l - 1;
    while (l < r) {
        int mid = l + r + 1 >> 1;
        if (a[mid] < val)
            l = mid;
        else
            r = mid - 1;
    }
    return l;
}

int main() {
    n = rad();
    rf(i, n) a[i] = rad();
    memset(min_ed, inf, sizeof(min_ed));
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int len = bin_search(min_ed, 1, i, a[i]) + 1;
        min_ed[len] = min(min_ed[len], a[i]);
        f[i] = len;
        ans = max(ans, f[i]);
    }
    printf("%d\n", ans);
}

int rad() {
    int back = 0, ch = 0, neg = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        neg = ch == '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return (back ^ -neg) + neg;
}